package net.hserver.admin.system.entity;


import cn.hserver.plugin.web.annotation.validate.NotBlank;
import cn.hserver.plugin.web.annotation.validate.NotNull;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.Getter;
import lombok.Setter;
import net.hserver.admin.system.enums.MenuTypeEnum;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

/**
 * 菜单信息
 *
*
 * @since 2022-06-27
 */
@Getter
@Setter
@Table("tab_menu")
public class Menu implements Serializable{

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @Id(value = "menu_id", keyType = KeyType.Auto)
    private Long menuId;

    /**
     * 菜单名称
     */
    private String menuName;

    /**
     * 菜单权限
     */
    private String permission;

    /**
     * 菜单类型
     */
    private MenuTypeEnum menuType;

    /**
     * 父菜单ID
     */
    private Long parentId;

    /**
     * 乐观锁
     */
    @Column(onUpdateValue = "version + 1")
    private Long version;

    /**
     * 逻辑删除
     */
    @Column(isLogicDelete = true)
    private Boolean deleted;

    /**
     * 创建时间
     */
    @Column(onInsertValue = "now()")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(onUpdateValue = "now()", onInsertValue = "now()")
    private LocalDateTime updateTime;

    /**
     * 子节点
     */
    @Column(ignore = true)
    private List<Menu> children;

    /**
     * 枚举中文
     */
    public String getMenuTypeLabel() {
        return Optional.ofNullable(this.menuType).orElse(MenuTypeEnum.DIR).getLabel();
    }


}
